package com.lxy.config;


import com.aliyun.dysmsapi20180501.Client;
import com.aliyun.teaopenapi.models.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(SendSmsProperties.class)
public class SendSmsConfig {


    @Autowired
    SendSmsProperties sendSmsProperties;


    @Bean
    public Client client(){

        Config config = new Config()
                .setAccessKeyId(sendSmsProperties.getAccessKeyId())
                .setEndpoint(sendSmsProperties.getEndpoint())
                .setAccessKeySecret(sendSmsProperties.getAccessKeySecret());

        try {
         return    new Client(config);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
}
